//
//  SZMainViewController.m
//  仿网易新闻
//
//  Created by made on 17/1/3.
//  Copyright © 2017年 made. All rights reserved.
//

#import "SZMainViewController.h"


@interface SZMainViewController ()

@end

@implementation SZMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor yellowColor];
    
    //添加子控制器
    [self addChildViewController];
    
    //设置tabbar的tintColor
    self.tabBar.tintColor = [UIColor cz_colorWithHex:0xdf0000];
}



//添加所有的子控制器
- (void)addChildViewController
{
    NSArray *parameters = @[
                            @{@"clsName":@"SZHomeViewController",@"title":@"首页",@"icon":@"news"},
                            @{@"clsName":@"UIViewController",@"title":@"阅读",@"icon":@"reader"},
                            @{@"clsName":@"UIViewController",@"title":@"视频",@"icon":@"media"},
                            @{@"clsName":@"UIViewController",@"title":@"话题",@"icon":@"bar"},
                            @{@"clsName":@"UIViewController",@"title":@"我",@"icon":@"me"},
                            ];
    //子控制器数组
    NSMutableArray *array = [NSMutableArray array];
    
    for (NSDictionary *dict in parameters)
    {
        UIViewController *controller = [self childViewControllerWithDic:dict];
        [array addObject:controller];
    }
    
    self.viewControllers = array;
}




//创建一个子控制器
- (UIViewController *) childViewControllerWithDic:(NSDictionary *) dict
{
    //用类名来创建一个控制器,这样就不需要导入头文件
    NSString *clsName = dict[@"clsName"];
    Class cls = NSClassFromString(clsName);
    UIViewController *controller = [cls new];
    
    //设置title
    controller.title = dict[@"title"];
    
    //设置tabbarItem的图标
    NSString *normalImageName = [NSString stringWithFormat:@"tabbar_icon_%@_normal",dict [@"icon"]];
    NSString *highlightImageName = [NSString stringWithFormat:@"tabbar_icon_%@_highlight",dict[@"icon"]];
    
    [controller.tabBarItem setImage:[UIImage imageNamed:normalImageName]];
    [controller.tabBarItem setSelectedImage:[[UIImage imageNamed:highlightImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    return controller;
    //return [[UINavigationController alloc] initWithRootViewController:controller];
}



@end
